package com.gxa.service.Impl;

import com.gxa.common.R;
import com.gxa.mapper.zhy.LoginMapper;
import com.gxa.pojo.Permission;
import com.gxa.pojo.Role;
import com.gxa.pojo.Users;
import com.gxa.pojo.zhy.Pr;
import com.gxa.service.LoginService;
import com.gxa.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: 赵贺益
 * Date: 2021/12/04 11:39
 * Description:
 * Version: V1.0
 */
@Service
public class LoginServiceImpl implements LoginService {
    @Autowired(required = false)
    private LoginMapper loginMapper;
    @Override
    public Users queryUserBy(String username, String user_passwords) {
        String user_password= MD5Utils.encrypt(user_passwords,MD5Utils.MD5_KEY);
        Users users=loginMapper.queryUserBy(username,user_password);
        return users;
    }

    @Override
    public R queryPermissionbyUsername(String username) {
        R r=new R();
//        List list=new ArrayList();
        List <Pr> prList=loginMapper.queryPermissionbyUsername(username);
        System.out.println(prList);
        if(prList!=null){
            r.setCode(200);
            r.setMsg("登录成功");
            r.setData(prList);
        }else {
            r.setCode(502);
            r.setMsg("该用户无权限");

        }

         return r;

    }
    /**
     * 根据登录账号获取该用户对应的权限角色
     */
    @Override
    public Role queryRoleNameByusername(String username) {
        Role role=loginMapper.queryRoleNameByusername(username);
        return role;
    }
    /**
     *获取该用户所有的可以操作的二级菜单
     */
    @Override
    public List<Permission> queryPermissionByUsername(String username) {
        List<Permission> permissionList=loginMapper.queryPermissionByUsername(username);
        return permissionList;
    }
}
